package br.com.delta.nota;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;
import br.com.delta.nota.R.layout;
import br.com.delta.view.LoginDialog;

public class InicioApp extends Activity {

	private static final int MAX = 100;
	private ProgressBar mProgress;
	private TextView    porcentagem;
	private int mProgressStatus = 0;

	private Handler mHandler = new Handler();

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(layout.inicio_app);

	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		mProgress = (ProgressBar) findViewById(R.id.progressBarSup);
		porcentagem = (TextView) findViewById(R.id.tvCarregando);
		

		// Start lengthy operation in a background thread
		new Thread(new Runnable() {
			public void run() {
				while (mProgressStatus < MAX) {
					mProgressStatus = simular();

					// Update the progress bar
					mHandler.post(new Runnable() {
						public void run() {
//							Log.i("Teste", "progresso = " + mProgressStatus);
							mProgress.setProgress(mProgressStatus);
							porcentagem.setText(mProgressStatus+"%");
							if(mProgressStatus == MAX){
								home();
							}
							

						}
					});
				}
			}
		}).start();

	}

	protected void home() {
		Intent home = new Intent(this, LoginDialog.class);
		startActivity(home);
		System.exit(0);
			

		
	}

	protected int simular() {
		// TODO Auto-generated method stub
		mProgressStatus++;
		try {
			Thread.sleep(100);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return mProgressStatus;
	}

    
}
